home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / GRAPHICS / IMGLIB95 / MMBLOB.PA_ / MMBLOB.PA
Text File  |  1996-03-31  |  16KB  |  504 lines

  1. {
  2. Written by Jan Dekkers and Kevin Adams (c) 1995, 1996. If you are a non
  3. registered client, you may use or alter this demo only for evaluation
  4. purposes.
  5.  
  6. Copyright by SkyLine Tools. All rights reserved.
  7.  
  8. Part of Imagelib VCL/DLL Library.
  9. }
  10.  
  11.  
  12. unit Mmblob;
  13.  
  14. {Includes settings to compile in either 16 or 32 bit}
  15. {$I DEFILIB.INC}
  16.  
  17. interface
  18.  
  19. uses
  20.    {$IFDEF DEL32}
  21.      Windows,
  22.    {$ELSE}
  23.      WinTypes,
  24.      WinProcs,
  25.    {$ENDIF}
  26.      DLL95V1,    {ImageLib Dll interface and misc. functions}
  27.      Classes,
  28.      Graphics,
  29.      Forms,
  30.      Controls,
  31.      Buttons,
  32.      StdCtrls,
  33.      ExtCtrls,
  34.      MPlayer,
  35.      DB,
  36.      DBTables,
  37.      DBCtrls,
  38.      Gauges,
  39.      SysUtils,
  40.      Dialogs,
  41.      Mask,
  42.      TDMULTIM;   {PDBMultiMedia1, PDBMultiImage VCL component}
  43.  
  44. type
  45.   TMMBlobForm = class(TForm)
  46.     CancelBtn: TBitBtn;
  47.     DataSource1: TDataSource;
  48.     Table1: TTable;
  49.     DBNavigator1: TDBNavigator;
  50.     Gauge1: TGauge;
  51.     OpenDialog1: TOpenDialog;
  52.     BitBtn1: TBitBtn;
  53.     CheckBox1: TCheckBox;
  54.     CheckBox2: TCheckBox;
  55.     OpenDialog2: TOpenDialog;
  56.     BitBtn2: TBitBtn;
  57.     DBEdit1: TDBEdit;
  58.     DBEdit2: TDBEdit;
  59.     DBMemo1: TDBMemo;
  60.     BitBtn3: TBitBtn;
  61.     CheckBox3: TCheckBox;
  62.     CheckBox4: TCheckBox;
  63.     BitBtn4: TBitBtn;
  64.     ScrollBar1: TScrollBar;
  65.     Panel1: TPanel;
  66.     BitBtn5: TBitBtn;
  67.     Panel2: TPanel;
  68.     BitBtn6: TBitBtn;
  69.     PrintDialog1: TPrintDialog;
  70.     BitBtn7: TBitBtn;
  71.     BitBtn8: TBitBtn;
  72.     DBMediaPlayer1: TPDBMediaPlayer;
  73.     DBMultiMedia1: TPDBMultiMedia;
  74.     CheckBox5: TCheckBox;
  75.     CheckBox6: TCheckBox;
  76.     CheckBox7: TCheckBox;
  77.     procedure CancelBtnClick(Sender: TObject);
  78.     procedure FormCreate(Sender: TObject);
  79.     procedure BitBtn1Click(Sender: TObject);
  80.     procedure CheckBox1Click(Sender: TObject);
  81.     procedure CheckBox2Click(Sender: TObject);
  82.     procedure BitBtn2Click(Sender: TObject);
  83.     procedure BitBtn3Click(Sender: TObject);
  84.     procedure CheckBox3Click(Sender: TObject);
  85.     procedure CheckBox4Click(Sender: TObject);
  86.     procedure BitBtn4Click(Sender: TObject);
  87.     procedure DataSource1DataChange(Sender: TObject; Field: TField);
  88.     procedure ScrollBar1Change(Sender: TObject);
  89.     procedure BitBtn5Click(Sender: TObject);
  90.     procedure BitBtn6Click(Sender: TObject);
  91.     procedure BitBtn7Click(Sender: TObject);
  92.     procedure BitBtn8Click(Sender: TObject);
  93.     procedure CheckBox5Click(Sender: TObject);
  94.     procedure CheckBox7Click(Sender: TObject);
  95.     procedure CheckBox6Click(Sender: TObject);
  96.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  97.   private
  98.     Procedure Trigger(Sender : TObject; Var Done : Boolean);
  99.     { Private declarations }
  100.   public
  101.     { Public declarations }
  102.   end;
  103.  
  104. var
  105.   MMBlobForm: TMMBlobForm;
  106.  
  107. implementation
  108.  
  109. {$R *.DFM}
  110. {---------------------------------------------------------------------}
  111.  
  112. procedure TMMBlobForm.CancelBtnClick(Sender: TObject);
  113. begin
  114. {close the app}
  115.  close;
  116. end;
  117. {---------------------------------------------------------------------}
  118.  
  119. {IMPORTANT}
  120. {Changed in version 2.21 from a procedure to a function with cdecl.
  121.  To cancel return a 0 else return a 1}
  122.  
  123. Function IwillBeCalled ( i : integer) : integer; cdecl; export;
  124. {Callback function from the dll, CDECL and EXPORT ARE REQUIRED}
  125.  
  126. begin
  127.   if Application.Terminated then
  128.  
  129.    {User wants to terminate the program. Pass a 0 to the dll}
  130.    Result:=0
  131.  
  132.   else begin
  133.    {Process Progress bar}
  134.    if MMBlobForm <> Nil then
  135.     MMBlobForm.Gauge1.Progress:=i;
  136.  
  137.    {Live in peace with others}
  138.    Application.ProcessMessages;
  139.  
  140.    {tell the dll that everything is OK}
  141.    Result:=1;
  142.    end;
  143. end;
  144. {---------------------------------------------------------------------}
  145.  
  146.  
  147. procedure TMMBlobForm.FormCreate(Sender: TObject);
  148. begin
  149.     {init label caption with file type}
  150.     Panel1.Caption:=DBMultiMedia1.BFiletype;
  151.  
  152.     {init label caption with file size}
  153.     Panel2.Caption:=IntToStr(DBMultiMedia1.Bsize)+ ' bytes';
  154.  
  155.     {On/Off Play the multimedia automatically}
  156.     DBMultiMedia1.AutoPlayMultiMedia:=CheckBox1.Checked;
  157.  
  158.     {On/Off Hide the DBMediaPlayer Automatically if MM is present}
  159.     DBMultiMedia1.AutoHideMediaPlayer:=CheckBox2.Checked;
  160.  
  161.     {On/Off RePlay the multimedia automatically}
  162.     DBMultiMedia1.AutoRePlayMultiMedia:=CheckBox4.Checked;
  163.  
  164.     {On/Off Display the multimedia automatically}
  165.     DBMultiMedia1.AutoDisplay:=CheckBox3.Checked;
  166.  
  167.     If FileExists(ExtractFilePath(Application.ExeName)+'mmblob.dbf') then begin
  168.        {if the table exists open it on creation}
  169.        Table1.DataBaseName:=ExtractFilePath(Application.ExeName);
  170.        Table1.TableName:='mmblob.dbf';
  171.        Table1.Active:=True;
  172.        {Show or hide the append/replace button, depending on
  173.        the table active stasus}
  174.        BitBtn7.Enabled:=Table1.Active;
  175.        BitBtn4.Enabled:=Table1.Active;
  176.        BitBtn3.Enabled:=Table1.Active;
  177.        BitBtn1.Enabled:=Table1.Active;
  178.      end;
  179.  
  180.    {IMPORTANT}
  181.     {This is the moving engine for all the messages. Since an application
  182.     can have only one OnIdle Trigger, this trigger needs to be subdivided
  183.     by all your moving and animated objects. In this particular case the
  184.     function is called TRIGGER but you can name it as you want as long
  185.     you have a procedure named the same.}
  186.  
  187.     {Register the callback Fuction to the VCL}
  188.     TPDBMultiMediaCallBack:=IwillBeCalled;
  189.  
  190.     Application.OnIdle:=Trigger;
  191.  end;
  192. {---------------------------------------------------------------------}
  193.  
  194. Procedure TMMBlobForm.Trigger(Sender : TObject; Var Done : Boolean);
  195. begin
  196.     {IMPORTANT}
  197.    {This function is called when your app is idle. Subdivide the
  198.     trigger event to your TDBMultiMedia objects who may need one.
  199.     If no Message is active it will not take up significant time}
  200.     DBMultiMedia1.Trigger;
  201. end;
  202. {---------------------------------------------------------------------}
  203.  
  204. procedure TMMBlobForm.BitBtn1Click(Sender: TObject);
  205. begin
  206.   {fill the OpenDialog filter with the MM extensions as found in the win.ini
  207.    (This means that the appropriate drivers are installed)}
  208.   OpenDialog1.filter:=GetMultiMediaExtensions;
  209.  
  210.   {Execute the open dialog box}
  211.   if OpenDialog1.Execute then begin
  212.  
  213.     {Place the Database in append mode}
  214.     Table1.Append;
  215.  
  216.     {Load the Multimedia into the Blob}
  217.     DBMultiMedia1.LoadfromFile(OpenDialog1.FileName);
  218.  
  219.     {Post that thing}
  220.     Table1.Post;
  221.   end;
  222. end;
  223. {---------------------------------------------------------------------}
  224.  
  225. procedure TMMBlobForm.BitBtn3Click(Sender: TObject);
  226. begin
  227.   {fill the OpenDialog filter with the MM extensions as found in the win.ini
  228.    (This means that the appropriate drivers are installed)}
  229.   OpenDialog1.filter:=GetMultiMediaExtensions;
  230.  
  231.   {Execute the open dialog box}
  232.   if OpenDialog1.Execute then begin
  233.  
  234.     {Place the Database in edit mode}
  235.     Table1.Edit;
  236.  
  237.     {Load the Multimedia into the Blob}
  238.     DBMultiMedia1.LoadfromFile(OpenDialog1.FileName);
  239.  
  240.     {Post that thing}
  241.     Table1.Post;
  242.   end;
  243. end;
  244. {---------------------------------------------------------------------}
  245.  
  246. procedure TMMBlobForm.CheckBox1Click(Sender: TObject);
  247. begin
  248.      {Play the appropriate multimedi when there}
  249.      DBMultiMedia1.AutoPlayMultiMedia:=CheckBox1.Checked;
  250. end;
  251. {---------------------------------------------------------------------}
  252.  
  253. procedure TMMBlobForm.CheckBox2Click(Sender: TObject);
  254. begin
  255.     {On/Off Hide the DBMediaPlayer Automatically if MM is present}
  256.      DBMultiMedia1.AutoHideMediaPlayer:=CheckBox2.Checked;
  257.  
  258.     if (Panel1.Caption = 'MID') or (Panel1.Caption = 'RMI') or (Panel1.Caption = 'WAV') then
  259.     {hide blob window if no media needs to be display and auto hide is on}
  260.      DBMultiMedia1.Visible:= not CheckBox2.Checked;
  261. end;
  262. {---------------------------------------------------------------------}
  263.  
  264. procedure TMMBlobForm.CheckBox3Click(Sender: TObject);
  265. begin
  266.     {On/Off Display the multimedia automatically}
  267.      DBMultiMedia1.AutoDisplay:=CheckBox3.Checked;
  268. end;
  269. {---------------------------------------------------------------------}
  270.  
  271. procedure TMMBlobForm.CheckBox4Click(Sender: TObject);
  272. begin
  273.     {On/Off RePlay the multimedia automatically}
  274.     DBMultiMedia1.AutoRePlayMultiMedia:=CheckBox4.Checked;
  275. end;
  276. {---------------------------------------------------------------------}
  277.  
  278. procedure TMMBlobForm.BitBtn2Click(Sender: TObject);
  279. begin
  280. {open the table}
  281.  try
  282.       If OpenDialog2.execute then begin
  283.         Table1.Active:=False;
  284.         Table1.DataBaseName:=ExtractFilePath(OpenDialog2.FileName);
  285.         Table1.TableName:=OpenDialog2.FileName;
  286.         Table1.Active:=True;
  287.       end;
  288.  finally
  289.         {Show or hide the append/replace button, depending on
  290.         the table active status}
  291.         BitBtn7.Enabled:=Table1.Active;
  292.         BitBtn4.Enabled:=Table1.Active;
  293.         BitBtn3.Enabled:=Table1.Active;
  294.         BitBtn1.Enabled:=Table1.Active;
  295.  end;
  296. end;
  297. {---------------------------------------------------------------------}
  298.  
  299. procedure TMMBlobForm.BitBtn4Click(Sender: TObject);
  300. begin
  301.     {Place the Database in append mode}
  302.     Table1.Append;
  303.     {Create a New Message}
  304.     If DBMultiMedia1.CreateMessage then
  305.     {Post or cancel that thing}
  306.        Table1.Post
  307.     else
  308.        Table1.Cancel;
  309. end;
  310. {---------------------------------------------------------------------}
  311.  
  312. procedure TMMBlobForm.BitBtn7Click(Sender: TObject);
  313. begin
  314.     {Place the Database in append mode}
  315.     Table1.Append;
  316.     {Create a New Credit Message}
  317.     If DBMultiMedia1.CreateCreditMessage then
  318.     {Post or cancel that thing}
  319.        Table1.Post
  320.     else
  321.        Table1.Cancel;
  322.   end;
  323. {---------------------------------------------------------------------}
  324.  
  325. procedure TMMBlobForm.DataSource1DataChange(Sender: TObject; Field: TField);
  326. var
  327.    temp : string;
  328. begin
  329.   {Show or hide the scroll bar}
  330.   ScrollBar1.Visible:=(DBMultiMedia1.BFiletype = 'SCM') or (DBMultiMedia1.BFiletype = 'CMS');
  331.  
  332.   {Syncronize the scrollbar's position}
  333.   ScrollBar1.Position:=DBMultiMedia1.MsgSpeed;
  334.  
  335.    {Set the blob window to visible}
  336.     DBMultiMedia1.Visible:=true;
  337.  
  338.     {Set the Video display rectangle to the rectangle of the blob window}
  339.     DBMediaPlayer1.DisplayRect:=Rect(0,0,DBMultiMedia1.Width,DBMultiMedia1.Height);
  340.  
  341.     {Set the Video display to the the display of the blob window}
  342.     DBMediaPlayer1.Display:=DBMultiMedia1;
  343.  
  344.     {init label caption with file type}
  345.     Panel1.Caption:=DBMultiMedia1.BFiletype;
  346.  
  347.     {init label caption with file size}
  348.     Panel2.Caption:=IntToStr(DBMultiMedia1.Bsize)+ ' bytes';
  349.  
  350.     {Get file type of blob stored}
  351.     temp:=DBMultiMedia1.BFiletype;
  352.  
  353.     {Show print button only when image is there}
  354.     BitBtn6.Enabled:= (DBMultiMedia1.Picture.Graphic <> nil);
  355.  
  356.     {Enable the next line. Just to show of (Play message if blob is a RMI file}
  357.     {if temp = 'RMI' then BitBtn5Click(Sender);}
  358.  
  359.     {Enable the next line. Just to show of (Play message if blob is a MIDI file}
  360.     {if temp = 'MID' then BitBtn8Click(Sender);}
  361.  
  362.  
  363.     if (temp = 'MID') or (temp = 'RMI') or (temp = 'WAV') then
  364.     {hide blob window if no media needs to be display and auto hide is on}
  365.     DBMultiMedia1.Visible:=not CheckBox2.Checked;
  366.  
  367. end;
  368. {---------------------------------------------------------------------}
  369.  
  370. procedure TMMBlobForm.ScrollBar1Change(Sender: TObject);
  371. begin
  372.   {Set message speed 1(fast) to 10(slow)}
  373.   DBMultiMedia1.MsgSpeed:=ScrollBar1.Position;
  374. end;
  375. {---------------------------------------------------------------------}
  376.  
  377. procedure TMMBlobForm.BitBtn5Click(Sender: TObject);
  378. begin
  379. begin
  380.    {create a message on the fly without actualy storing the message in the blob
  381.    At any time you can play this message}
  382.    {set Message text}
  383.     DBMultiMedia1.MsgText:='Isn''t super to be a Delphi programmer ?? '+
  384.     'Delphi is too Cool and so is every one who''s using VCL''s !! ';
  385.     {set Message font name;  Note you could do this also with a font dialog}
  386.     DBMultiMedia1.MsgFont.Name:='Arial';
  387.    {set Message font size}
  388.     DBMultiMedia1.MsgFont.Size:=-30;
  389.     {set Message font style}
  390.     DBMultiMedia1.MsgFont.Style:=[fsItalic];
  391.     {set Message font color}
  392.     DBMultiMedia1.MsgFont.Color:=clWhite;
  393.     {set Message background. Note you could do this also with a color dialog}
  394.     DBMultiMedia1.MsgBkGrnd:=clTeal;
  395.     {set Message speed from 0 is fast to 10 is slow}
  396.     DBMultiMedia1.MsgSpeed:=0;
  397.     {show the speed control scroll bar}
  398.     ScrollBar1.Visible:=True;
  399.     {Set position according speed}
  400.     ScrollBar1.Position:=DBMultiMedia1.MsgSpeed;
  401.     {inititiate new message}
  402.     DBMultiMedia1.NewMessage;
  403.   end;
  404. end;
  405. {---------------------------------------------------------------------}
  406.  
  407. procedure TMMBlobForm.BitBtn6Click(Sender: TObject);
  408. begin
  409. {print image x y width and heigth (if width and heigth are 0 the image
  410. original size is printed)}
  411.  If PrintDialog1.Execute then
  412.   DBMultiMedia1.PrintMultiImage(0,0,0,0);
  413. end;
  414. {---------------------------------------------------------------------}
  415.  
  416. procedure TMMBlobForm.BitBtn8Click(Sender: TObject);
  417. begin
  418.    {Create A credit message on the fly}
  419.     DBMultiMedia1.FreeMsg;
  420.    {Clear Message text if any}
  421.     DBMultiMedia1.CreditBoxList.Clear;
  422.    {Define Message text}
  423.     DBMultiMedia1.CreditBoxList.Add(' ImageLib');
  424.     DBMultiMedia1.CreditBoxList.Add(' Another fine product of');
  425.     DBMultiMedia1.CreditBoxList.Add(' SKYLINE TOOLS');
  426.     DBMultiMedia1.CreditBoxList.Add(' Programming : Kevin Adams');
  427.     DBMultiMedia1.CreditBoxList.Add(' Programming : Jan Dekkers');
  428.     DBMultiMedia1.CreditBoxList.Add(' Artwork & PR: Jillian Pinsker');
  429.  
  430.     {set Message font name;  Note you could do this also with a font dialog}
  431.     DBMultiMedia1.MsgFont.Name:='Arial';
  432.    {set Message font size}
  433.     DBMultiMedia1.MsgFont.Size:=-14;
  434.     {set Message font style}
  435.     DBMultiMedia1.MsgFont.Style:=[fsbold];
  436.     {set Message font color}
  437.     DBMultiMedia1.MsgFont.Color:=clWhite;
  438.     {set Message background. Note you could do this also with a color dialog}
  439.     DBMultiMedia1.MsgBkGrnd:=clNavy;
  440.     {set Message speed from 1 is fast to 10 is slow}
  441.     DBMultiMedia1.MsgSpeed:=5;
  442.     {Show Speed ScrollBar}
  443.     DBMultiMedia1.Visible:=true;
  444.     {set the speed/position}
  445.     ScrollBar1.Position:=DBMultiMedia1.MsgSpeed;
  446.     {inititiate new message}
  447.     DBMultiMedia1.NewCreditMessage;
  448. end;
  449. {---------------------------------------------------------------------}
  450.  
  451. {---------------------------------------------------------------------}
  452.  
  453. procedure TMMBlobForm.CheckBox5Click(Sender: TObject);
  454. begin
  455.  {Stretch DBImage}
  456.  if CheckBox7.Checked then begin
  457.     DBMultiMedia1.StretchRatio:=False;
  458.     CheckBox7.Checked:=False;
  459.  end;
  460.  DBMultiMedia1.Stretch:=CheckBox5.Checked;
  461.  DBMultiMedia1.Update;
  462. end;
  463. {---------------------------------------------------------------------}
  464.  
  465. procedure TMMBlobForm.CheckBox7Click(Sender: TObject);
  466. begin
  467.  {Stretch ratio DBImage}
  468.  if CheckBox5.Checked then begin
  469.     DBMultiMedia1.Stretch:=False;
  470.     CheckBox5.Checked:=False;
  471.  end;
  472.  DBMultiMedia1.StretchRatio:=CheckBox7.Checked;
  473.  DBMultiMedia1.Update;
  474. end;
  475. {---------------------------------------------------------------------}
  476.  
  477. procedure TMMBlobForm.CheckBox6Click(Sender: TObject);
  478. begin
  479.   {Use the ImageLib way of drawing. This is a 256 color problem
  480.    workaround caused by some VGA driver in delphi}
  481.   DBMultiMedia1.ImageLibPalette:=CheckBox6.Checked;
  482.   DBMultiMedia1.Invalidate;
  483. end;
  484.  
  485. procedure TMMBlobForm.FormClose(Sender: TObject; var Action: TCloseAction);
  486. begin
  487.     {UNRegister the callback Fuction to the VCL}
  488.     TPDBMultiMediaCallBack:=Nil;
  489.     Application.OnIdle:=Nil;
  490.     MMBlobForm:=Nil;
  491.     Action:=caFree;
  492. end;
  493.  
  494. end.
  495.  
  496. {---------------------------------------------------------------------}
  497.  
  498. {easy enough ?}
  499.  
  500. {---------------------------------------------------------------------}
  501.  
  502.  
  503.  
  504.